package com.jluzh10.learning.web.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.jluzh10.learning.domain.CourseGroup;
import com.jluzh10.learning.service.CourseGroupService;
import com.jluzh10.learning.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author yzg
 * @create 2019/5/25
 */
@Controller
@RequestMapping("group")
public class CourseGroupController {
    private final CourseGroupService groupService;

    @Autowired
    public CourseGroupController(CourseGroupService groupService) {
        this.groupService = groupService;
    }

    /**
     * 查询课程分组列表
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.GET)
    @ResponseBody
    public ResponseData find(Integer size) throws Exception {
        List<CourseGroup> groups = groupService.findAll(size);
        return new ResponseData().success("查询成功").data(groups);
    }

    /**
     * 添加一个课程分组
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData add(CourseGroup group) throws Exception {

        int i = groupService.add(group);
        return new ResponseData().success("添加成功").data(group);
    }
}
